#include<bits/stdc++.h>
using namespace std;

int t,n,a[200002],ls[200002],la[1000002],c[200002];
long long ans;

int main(){
	
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	
	cin>>t;
	for(;t;t--){
		cin>>n;
		memset(la,0,sizeof(la));
		ans=0;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			ls[i]=la[a[i]];
			la[a[i]]=i;
		}
		
		int cl=0;
		for(int i=n;i>=1;i--){
			if(c[i]==0&&ls[i]!=0){
				ans+=a[i];
				c[i]=cl+1;
				c[ls[i]]=cl+1;
				cl=(cl+1)%2;
			}
		}
		cout<<ans<<'\n';
	}
	
	return 0;
}
